//
//  VisitorTableViewController.swift
//  WeoboWithSteveLi
//
//  Created by SteveLi on 2017/9/18.
//  Copyright © 2017年 李军桦. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    /// 用户登录标记
    /**
        1.应用程序中有几个visitorView   ----> 4 个
        2.访客视图如果用懒加载会怎样？ 如果使用懒加载，访客视图始终都会被创建出来
    */
    var userLogin = UserAccountViewModel.sharedUserAccount.userLogon
    //访客视图
    var visitorView: VisitorView?
    override func loadView() {
        //根据用户登录情况，决定显示根视图
        userLogin ? super.loadView() : setupVisitorView()
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
       // print(visitorView)
    }
    /// 设置访客视图
    func setupVisitorView() {
        //替换根视图
         visitorView = VisitorView()
        //设置代理
        view = visitorView
        //添加监听方法
        visitorView?.registerButton.addTarget(self, action:#selector(visitorViewDidRegister), for: .touchUpInside)
        visitorView?.loginButton.addTarget(self, action: #selector(visitorViewDidLogin), for: .touchUpInside)
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(visitorViewDidRegister))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(visitorViewDidLogin))
    }
}

//MARK: -访客视图监听方法
extension VisitorTableViewController {
    func visitorViewDidRegister() {
            print("注册")
    }
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        present(nav, animated: true, completion: nil)
    }
    
}










